<template>
  <div class="tab-bar-item" @click="itemClick">
    <slot v-if="!isActive" name="item-coin"></slot>
    <slot v-else name="item-coin-active"></slot>
    <div :class="{active:isActive}"><slot name="item-text"></slot></div>
  </div>
</template>

<script>
export default {
  name: "TabBarItem",
  props:{
    link: String
  },
  data(){
    return{
      //isActive:true
    }
  },
  computed:{
    isActive(){ //匹配当前活跃路由和路由列，赋予状态   不匹配返回-1
      return this.$route.path.indexOf(this.link)!==-1
    }
  },
  methods:{
    itemClick(){
      this.$router.replace(this.link)
    }
  }
}
</script>

<style scoped>
.tab-bar-item{
  text-align: center;
  flex: 1;
  height: 49px;
}
.tab-bar-item img{
  width: 24px;
  height: 24px;
}
.active{
  color:red;
}
</style>